alter function f_getuserlist
(
  @string nvarchar(200)
)
RETURNS varchar(200)
as
begin
  DECLARE @position int, @r varchar(200), @userid int,@suser varchar(60),@username varchar(60)
  set @position = charindex(',',@string)
  set @r=','
  WHILE @position > 0
  BEGIN
    if @position=1
    begin
      set @string=substring(@string,2,len(@string))
    end
    else
    begin
      set @suser=substring(@string, 1, @position-1)
      set @userid=cast(@suser as int)
      select @username=ui_username from ts_usersinfo where ui_userid=@userid
      if @username is not null
        select @r=@r+@username+','
      set @string=substring(@string,@position,len(@string))      
    end
    set @position = charindex(',',@string)
  END
  RETURN @r
end